﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;
using SharePoint.Contrib.Extensions;
using Microsoft.SharePoint;
using System.Diagnostics;

namespace NUnit.SharePointContrib
{
    [TestFixture]
    public class SPListItemExtensionsTest
    {

        SPSite sitecollection = null;
        SPWeb root = null;
        SPList list = null;
        const string ListName = "SPListItemExtensionsTest";

        [SetUp]
        public void Init()
        {
            if (SharePoint.TryFindSiteCollection(out sitecollection))
            {
                root = sitecollection.RootWeb;
                Guid id = root.Lists.Add(ListName, "", SPListTemplateType.GenericList);
                list = root.Lists[id];
            }
        }

        [TearDown]
        public void Dispose()
        {
            list.Delete();
            sitecollection.Dispose();
        }


        [Test]
        public void CanFindDispFormUrl()
        {
            var item = list.Items.Add();
            item.Update();

            var dispform = item.DispFormUrl();

            Assert.That(string.Format("{0}/DispForm.aspx?id={1}", list.RootFolder.ServerRelativeUrl, item.ID), Is.EqualTo(dispform));
        }

        [Test]
        public void CanFindEditFormUrl()
        {
            var item = list.Items.Add();
            item.Update();

            var editform = item.EditFormUrl();

            Assert.That(string.Format("{0}/EditForm.aspx?id={1}", list.RootFolder.ServerRelativeUrl, item.ID), Is.EqualTo(editform));
        }

        [Test]
        public void CanFindNewFormUrl()
        {
            var item = list.Items.Add();
            item.Update();

            var newform = item.NewFormUrl();

            Assert.That(string.Format("{0}/NewForm.aspx?id={1}", list.RootFolder.ServerRelativeUrl, item.ID), Is.EqualTo(newform));
        }

    
    }
}
